# coding: utf8

db.define_table("pdf_template",
    Field("pdf_template_id","id"),
    Field("title"),
    Field("format", requires=IS_IN_SET(["A4","legal","letter"])),
)

db.define_table("pdf_element",
    Field("pdf_template_id", db.pdf_template, requires=IS_IN_DB(db,'pdf_template.pdf_template_id', 'pdf_template.title')),
    Field("name", requires=IS_NOT_EMPTY()),
    Field("type", length=2, requires=IS_IN_SET(['T', 'L', 'I', 'B', 'BC'])),
    Field("x1", "double", requires=IS_NOT_EMPTY()),
    Field("y1", "double", requires=IS_NOT_EMPTY()),
    Field("x2", "double", requires=IS_NOT_EMPTY()),
    Field("y2", "double", requires=IS_NOT_EMPTY()),
    Field("font", default="Arial", requires=IS_IN_SET(['Courier','Arial','Times','Symbol','Zapfdingbats'])),
    Field("size", "double", default="10", requires=IS_NOT_EMPTY()),
    Field("bold", "boolean"),
    Field("italic", "boolean"),
    Field("underline", "boolean"),
    Field("foreground", "integer", default=0x000000, comment="Color text"),
    Field("background", "integer", default=0xFFFFFF, comment="Fill color"),
    Field("align", "string", length=1, default="L", requires=IS_IN_SET(['L', 'R', 'C', 'J'])),
    Field("text", "text", comment="Default text"),
    Field("priority", "integer", default=0, comment="Z-Order"),
    )


# initialization.py
# created from plugin_plugin/template_plugin_initialization_py
# copyright christopher steel, 2011, on behalf of Voice of Access
import os
cwd = os.getcwd()
current_app = os.path.join(cwd,'applications',request.application)
#initialization_file_path = os.path.join(current_app,'models','plugin_uc_pyfpdf','000_uc_initialization.py')
initialization_file_path = os.path.join(current_app,'models','000_uc_initialization.py')

# create an initialization file if we do not have one
if not 'initialization_file_created' in globals():
    if not os.path.exists(initialization_file_path):
        our_file = open(initialization_file_path,"w")
        our_text = '# file created by plugin_uc_pyfpdf\n'
        our_text += 'initialization_file_created = True\n'
        our_file.writelines(our_text)
        our_file.close()
else:
    print('models/plugin_uc_pyfpdf/initialization.py found')
    print('initialization_file_created globals')


if not 'group_plugin_uc_pyfpdf_admin_created' in globals():
    if not db(db.auth_group.role=='plugin_uc_pyfpdf_admin').select(): 
        db.auth_group.insert(role='plugin_uc_pyfpdf_admin',description='user to administer plugin_uc_pyfpdf')
        our_file = open(initialization_file_path,"a")
        our_text = '# entry created by plugin_uc_pyfpdf\n'
        our_text += 'group_plugin_uc_pyfpdf_admin_created = True\n'
        our_file.write(our_text)
        our_file.close()
else:
    print('models/plugin_uc_pyfpdf/initialization.py found')
    print('group_plugin_uc_pyfpdf_admin_created globals')

##
response.menu_plugin_uc_fpdfpdf_index = [
    (T('Plugin uc_pyfpdf'), False, URL('plugin_uc_pyfpdf','index'), [])
    ]

response.menu_plugin_uc_fpdfpdf_voa_contribution_confirmation_fr = [
    (T('voa_contribution_confirmation_fr'), False, URL('plugin_uc_pyfpdf','voa_contribution_confirmation_fr'), [])
    ]

response.menu_plugin_uc_fpdfpdf_voa_contribution_confirmation_en = [
    (T('voa_contribution_confirmation_en'), False, URL('plugin_uc_pyfpdf','voa_contribution_confirmation_en'), [])
    ]

#response.menu_plugin_uc_fpdfpdf_voa_business_cards_en_en = [
#    (T('voa_business_cards_en'), False, URL('plugin_uc_pyfpdf','voa_business_cards_en'), [])
#    ]

response.menu_plugin_uc_fpdfpdf = []
response.menu_plugin_uc_fpdfpdf += response.menu_plugin_uc_fpdfpdf_index
response.menu_plugin_uc_fpdfpdf += response.menu_plugin_uc_fpdfpdf_voa_contribution_confirmation_fr
response.menu_plugin_uc_fpdfpdf += response.menu_plugin_uc_fpdfpdf_voa_contribution_confirmation_en
# response.menu_plugin_uc_fpdfpdf += response.menu_plugin_uc_fpdfpdf_voa_business_cards_en
response.menu += response.menu_plugin_uc_fpdfpdf

##

response.menu+= [
    (T('plugin_uc_pyfpdf'), False, URL('plugin_uc_pyfpdf','index'),
        [
            (T('plugin_uc_pyfpdf actions'), False, URL('plugin_uc_pyfpdf','index'),
                [
                    (T('simple_template'), False, URL('plugin_uc_pyfpdf', 'simple_template')),
                    (T('get_me_a_pdf'), False, URL('plugin_uc_pyfpdf', 'get_me_a_pdf')),
                    (T('get_me_a_pyfpdf'), False, URL('plugin_uc_pyfpdf', 'get_me_a_pyfpdf')),
                    (T('report'), False, URL('plugin_uc_pyfpdf', 'report')),
                    (T('listing'), False, URL('plugin_uc_pyfpdf', 'listing')),
                    (T('import_cvs'), False, URL('plugin_uc_pyfpdf', 'import_cvs')),
                    (T('voa_invoice'), False, URL('plugin_uc_pyfpdf', 'voa_invoice')),
                    (T('invoice'), False, URL('plugin_uc_pyfpdf', 'invoice')),
                ]),
            (T('about'), False, URL(request.application,'plugin_uc_pyfpdf','display_static',args='about')),
            (T('license'), False, URL(request.application,'plugin_uc_pyfpdf','display_static',args='license')),
        ]
   )]
